package com.qf.android.huihui.adapter.shopping;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.show.shoppingbottom.ShoppingBottomBean;
import com.qf.android.huihui.common.IClickListern;

import java.util.List;

/**
 * Created by 韩爽 on 2017/1/13.
 */

public class ShoppingHuiItemAdapter extends ShoppingBaseAdapter {
    private List<ShoppingBottomBean.DataBean.ListBeanXX.HuiItemBean> list;
    private Context context;

    public ShoppingHuiItemAdapter(List<ShoppingBottomBean.DataBean.ListBeanXX.HuiItemBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.fragment_shopping_huiitem_item,parent,false);
        MyHolder myHolder=new MyHolder(view,listern);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ShoppingBottomBean.DataBean.ListBeanXX.HuiItemBean bean = list.get(position);
        MyHolder holder1 = (MyHolder) holder;
        Glide.with(context).load(bean.getImageUrl()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder1.imageView);
        holder1.textView_title.setText(bean.getTitle());
        holder1.textView_content.setText(bean.getSubTitle());
        holder1.textView_shop.setText(bean.getMerchant().getName());
        holder1.textView_count.setText(bean.getCommentsCount()+"");
        holder1.itemView.setTag(bean.getUrl());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void setMyClickListener(IClickListern listener) {
        this.listern=listener;
    }

    public class MyHolder extends ShoppingBaseAdapter.MyHolder {
        private ImageView imageView;
        private TextView textView_shop;
        private TextView textView_count;
        private TextView textView_title;
        private TextView textView_content;
        private IClickListern listern;

        public MyHolder(View itemView, IClickListern listern) {
            super(itemView, listern);
            this.listern=listern;
            imageView= (ImageView) itemView.findViewById(R.id.huiitem_item_imageview);
            textView_shop= (TextView) itemView.findViewById(R.id.huiitem_item_shop);
            textView_count= (TextView) itemView.findViewById(R.id.huiitem_item_count);
            textView_title= (TextView) itemView.findViewById(R.id.huiitem_item_title);
            textView_content= (TextView) itemView.findViewById(R.id.huiitem_item_content);

        }

        @Override
        public void onClick(View v) {
            if(listern!=null){
                listern.OnItemClick(v,(String)v.getTag());
            }
        }
    }
}
